@using SmartCode
@using SmartCode.Db;
@model BuildContext
@{
    Layout = "_JavaLayout.cshtml";
    var project = Model.Project;
    var buildTask = Model.Build;
    var table = Model.GetCurrentTable();
    var pkCol = table.PKColumn;
    if (pkCol == null)
    {
        throw new SmartCodeException($"Repository Template can not find PKColumn,Table:{table.Name}.");
    }
    var primaryKeyType = pkCol.LanguageType ?? "int";
    switch (primaryKeyType)
    {
        case "long":
        {
            primaryKeyType = "Long";
            break;
        }
        case "int":
        {
            primaryKeyType = "Integer";
            break;
        }
    }
    var dbSource = Model.GetDataSource<DbSource>();

    String genericRepositoryPackageName = "";
    if (buildTask.Parameters.TryGetValue("GenericRepository", out var _genericRepositoryParams))
    {
        var genericRepositoryParams = (Dictionary<Object, Object>) _genericRepositoryParams;
        if (!genericRepositoryParams.TryGetValue("Package", out var _genericRepositoryPackage))
        {
            throw new ArgumentException("GenericRepository.Package can not be null.");
        }
        genericRepositoryPackageName = _genericRepositoryPackage.ToString();
    }
    
    if (!project.BuildTasks.TryGetValue("Entity", out var entityBuild))
    {
        throw new ArgumentException("can not find Project -> BuildTasks -> [Entity] .");
    }
    var genericParameterKey = $"{table.ConvertedName},{primaryKeyType}";
}

package @(project.Module).@buildTask.Module;

import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import @(genericRepositoryPackageName).GenericRepository;
import @(project.Module).@(entityBuild.Module).@table.ConvertedName;

@Html.NewLine()
@@Repository
@@Mapper
public interface @(table.ConvertedName)Repository extends GenericRepository<@genericParameterKey> {

}